package testDao;

import com.fang.bean.userBean;
import com.fang.dao.IPUserDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class testProvider {
    @Test
    public void test1(){
        String resource = "mybatis-config.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);

            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            try (SqlSession session = sqlSessionFactory.openSession()) {
                IPUserDao userMapper = session.getMapper(IPUserDao.class);
                userBean userB = userMapper.userMassageId(2);
                System.out.println("查询的结果：");
                System.out.println(userB);
            }
            try (SqlSession session = sqlSessionFactory.openSession()) {
                userBean userB =  session.selectOne("com.fang.dao.IPUserDao.userMassageId", 2);


            }
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
    @Test
    public void test(){
        String resource = "mybatis-config.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);

            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            try (SqlSession session = sqlSessionFactory.openSession()) {
                userBean userB =  session.selectOne("com.fang.dao.IPUserDao.userMassageId", 2);

                System.out.println("查询的结果：");
                System.out.println(userB);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
    public static void main(String[] args) {

        String resource = "mybatis-config.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);

            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            try (SqlSession session = sqlSessionFactory.openSession()) {
               userBean userB =  session.selectOne("com.fang.dao.IPUserDao.userMassageId", 2);

                System.out.println("查询的结果：");
                System.out.println(userB);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
